import java.util.Arrays;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: XMQ
 * Date: 2022-06-19
 * Time: 20:39
 */
//几个排序算法
public class Test {
    public static int quickSort(int[] nums, int left, int right){
        if (left >= right)
            return 0;
        int pivot = left;
        int key = nums[left];
        while(left < right){
            while(left < right && nums[right] >= key){
                right--;
            }
            nums[pivot] = nums[right];
            pivot = right;
            while(left < right && nums[left] <= key){
                left++;
            }
            nums[pivot] = nums[left];
            pivot = left;
        }
        nums[pivot] = key;
        return pivot;
    }
    public static void bubbleSort(int[] nums){
        for (int i = 0; i < nums.length; i++) {
            boolean flg = false;
            for (int j = 0; j < nums.length - i-1; j++) {
                if(nums[j] > nums[j+1]){
                    int tmp = nums[j];
                    nums[j] = nums[j+1];
                    nums[j+1] = tmp;
                    flg = true;
                }
            }
            if(flg == false) break;
        }
    }
    public static void sort(int[] nums, int left, int right){
        if (left >= right)
            return;
        int pivot = quickSort(nums,left,right);
        sort(nums,left,pivot-1);
        sort(nums,pivot+1,right);
    }
    public static void main(String[] args) {
        int[] nums = {32,65,345,12,5,76,321,56,22};
//        bubbleSort(nums);
        sort(nums,0,nums.length-1);
        System.out.println(Arrays.toString(nums));
    }
}
